package com.example.user.service;


import com.example.user.common.Result;
import com.example.user.entity.Order;
import com.example.user.mapper.OrderMapper;
import com.example.user.request.CartRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {


    @Autowired
    private OrderMapper orderMapper;

    public Result createOrder(CartRequest cartRequest) {

       int count= orderMapper.insertOrder(cartRequest);
       if(count==0)
       {
           return Result.error("400","生成失败");
       }
       return Result.success("生成成功");
    }

    public List<Order> getOrderPage(Integer userId) {
      List<Order> orderList= orderMapper.getOrderPage(userId);
      return orderList;
    }

    public Result updateOrderStatusByUser(Order order) {
       int count= orderMapper.updateOrderStatusByUser(order);
               if(count==0)
               {
                   return Result.error("400","修改失败");
               }
               return Result.success("修改成功");
    }
}
